package cn.com.ccxe.web.form;


import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

public abstract class ActionForm {

	private HttpServletRequest request;

	public ActionForm(HttpServletRequest request) {
		this.request = request;
		reset();
	}

	public String getParemetes(String name) {
		return request.getParameter(name);
	}

	public String[] getParameterValues(String name) {
		return request.getParameterValues(name);
	}

	public Object getAttribute(String name) {
		Object obj = request.getAttribute(name);
		if (obj == null) {
			obj = request.getSession().getAttribute(name);
		}
		return obj;
	}
	
	@SuppressWarnings("unchecked")
	public void testForm(HttpServletRequest request) {
		Enumeration enu = request.getParameterNames();
		while (enu.hasMoreElements()) {
			String name = (String) enu.nextElement();
			// 如果是数组参数，则逐个打印
			System.out.println(name);
			String canshu[] = request.getParameterValues(name);
			for (int i = 0; i < canshu.length; i++) {
				System.out.println(canshu[i]);
			}
		}
	}
	
	protected abstract void reset();
}
